--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_doremi_sweet = General:new(extension, "hy_doremi_sweet", "ten_k", 3, 3, General.Female)
    local real_dream = fk.CreateSkill {
        name = "real_dream",
    }
    real_dream:addEffect(fk.BeforeTurnStart, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(real_dream.name) and player == target and player:usedSkillTimes(real_dream.name, Player.HistoryRound) < 1
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            event:setCostData(self, table.map(room:askToChoosePlayers(player, {
                targets = room.alive_players,
                min_num = 1,
                max_num = 1,
                prompt = "real_dream_prompt",
                skill_name = real_dream.name
            }), Util.IdMapper))
            return #event:getCostData(self) > 0
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:getPlayerById(event:getCostData(self)[1]):gainAnExtraTurn(false)
        end,
    })
    real_dream:addEffect(fk.HpRecover, {
        is_delay_effect = true,
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            local room = player.room
            if player:hasSkill(real_dream.name) and target:insideExtraTurn() and target:getCurrentExtraTurnReason() == real_dream.name then
                return #room.logic:getEventsOfScope(GameEvent.Recover, 2, function(e)
                    return e.data.who == target
                end, Player.HistoryTurn) == 1
            end
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if not player.dead then
                player:drawCards(1, real_dream.name)
                local e = room.logic:getCurrentEvent()
                while e.parent and e.parent.event ~= GameEvent.Phase do
                    e = e.parent
                end
                e:addExitFunc(function()
                    local parent = e:findParent(GameEvent.Turn)
                    if parent then
                        parent.killed = true
                        parent:shutdown()
                    end
                end)
            end
        end,
    })
    real_dream:addEffect(fk.Damage, {
        is_delay_effect = true,
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            local room = player.room
            if player:hasSkill(real_dream.name) and data.from and target:insideExtraTurn() and target:getCurrentExtraTurnReason() == real_dream.name then
                return #room.logic:getEventsOfScope(GameEvent.Damage, 2, function(e)
                    return e.data.from == target
                end, Player.HistoryTurn) == 1
            end
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if not player.dead then
                player:drawCards(1, real_dream.name)
                local e = room.logic:getCurrentEvent()
                while e.parent and e.parent.event ~= GameEvent.Phase do
                    e = e.parent
                end
                e:addExitFunc(function()
                    local parent = e:findParent(GameEvent.Turn)
                    if parent then
                        parent.killed = true
                        parent:shutdown()
                    end
                end)
            end
        end,
    })
    local dream_master = fk.CreateSkill {
        name = "dream_master",
    }
    dream_master:addEffect(fk.TurnStart, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(dream_master.name) and target ~= player and not target:isKongcheng() and target:insideExtraTurn()
        end,
        on_cost = function(self, event, target, player, data)
            return player.room:askToSkillInvoke(player, {
                skill_name = dream_master.name,
                prompt = "dream_master_prompt::" .. target.id
            })
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local count = #target:getCardIds("h")
            room:obtainCard(player, target:getCardIds("h"), false, fk.ReasonPrey)
            if #player:getCardIds("h") > count then
                local result = room:askToCards(player, {
                    min_num = count,
                    max_num = count,
                    skill_name = dream_master.name,
                    cancelable = false,
                    pattern = ".|.|.|hand"
                })
                room:moveCards({
                    from = player,
                    toArea = Card.PlayerHand,
                    to = target,
                    proposer = player,
                    ids = result,
                    skillName = dream_master.name,
                    moveReason = fk.ReasonGive,
                    moveVisible = false,
                })
            elseif #player:getCardIds("h") > 0 then
                room:delay(2000)
                room:moveCards({
                    from = player,
                    toArea = Card.PlayerHand,
                    to = target,
                    proposer = player,
                    ids = player:getCardIds("h"),
                    skillName = dream_master.name,
                    moveReason = fk.ReasonGive,
                    moveVisible = false,
                })
            end
        end
    })
    extension:loadSkillSkels { real_dream, dream_master }
    hy_doremi_sweet:addSkill("real_dream")
    hy_doremi_sweet:addSkill("dream_master")
    Fk:loadTranslationTable {
        ["hy_doremi_sweet"] = "哆来咪苏伊特",
        ["#hy_doremi_sweet"] = "幻梦百解",
        ["illustrator:hy_doremi_sweet"] = "こざくら",
        ["designer:hy_doremi_sweet"] = "黑曜人形",
        ["cv:hy_doremi_sweet"] = "",

        ["real_dream"] = "现梦",
        [":real_dream"] = "每轮限一次，回合开始前，你可以令一名角色立即执行一个额外回合，当其于此额外回合第一次造成伤害或回复体力后，你摸一张牌并结束此回合。",
        ["real_dream_prompt"] = "现梦：你可以令一名角色执行一个额外回合",

        ["dream_master"] = "眠主",
        [":dream_master"] = "其他角色的额外回合开始时，你可以获得其全部手牌然后交给其等量的手牌。",
        ["dream_master_prompt"] = "眠主：你可以获得%dest全部手牌然后交给其等量的手牌",
    }
end
